package com.sky;

/**
 * @author : wushikai
 * <p>
 * date : 2021/8/10
 */
public class StackTraceElementTest {

    public static void testStackTraceElement() throws ClassNotFoundException {
        //获取堆栈轨迹数组
        StackTraceElement[] elements = Thread.currentThread().getStackTrace();
        for (int i = 0; i < elements.length; i++) {
            System.out.println(elements[i]);
        }


        System.out.println("/*-------------------------------------   --------------------------------------------*/");

        //springboot 加载主类
        for (StackTraceElement stackTraceElement : elements) {

            System.out.println(stackTraceElement.getClassName());
            System.out.println(stackTraceElement.getMethodName());
            System.out.println(stackTraceElement.getMethodName());

            if ("main".equals(stackTraceElement.getMethodName())) {
                Class<?> clazz = Class.forName(stackTraceElement.getClassName());
                System.out.println("主类==> " + clazz.getCanonicalName());

            }
        }
    }


    public static void main(String[] args) throws ClassNotFoundException {
        testStackTraceElement();


    }

}
